package brickBreaker;


import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Rectangle;

import states.SlickGame;
import globals.FreeVector;
import interfaces.Controllable;
import interfaces.Trackable;

public class Paddle extends Controllable{
	int paddleLength=50, paddleWidth=20;
	int speed=1;
	Color paddleColor=new Color((float)0.1,(float)0.2,(float)0.8);
	
	public Paddle(int xpos, int ypos) {
		super();
		x=xpos-paddleLength/2;
		y=ypos-paddleWidth/2;
		r=paddleLength;
	}
	// pi/2 ~= 4.712389
	
	public void update(Ball ball){
		
		if(ball.y>=this.y && ball.x==this.x){// hits center
			ball.direction.add(new FreeVector(6,(float)((3*Math.PI)/2)));
		}
		else if(ball.y>=this.y && ball.x<this.x && ball.x>this.x-paddleLength/2){ // hits left
			ball.direction.add(new FreeVector(6,(float)4.5));
		}
		else if(ball.y>=this.y && ball.x<this.x+paddleLength/2 && ball.x>this.x){ // hits right
			ball.direction.add(new FreeVector(6,(float)4.8));
		}
		
		if(this.checkSpecial()){speed=15;}
		else {speed=5;}
		
		if(this.checkLeft()){
			x-=speed;
		}
		if(this.checkRight()){
			x+=speed;
		}
		if(x<0){x=0;}
		if(x>SlickGame.width-paddleLength/2){x=SlickGame.width-paddleLength/2;}
	}
	
	public void draw(Graphics g){
		g.setColor(paddleColor);
		g.fill(new Rectangle(x-paddleLength/2, y-paddleWidth/2, paddleLength, paddleWidth));
		g.setColor(paddleColor.darker());
		g.setLineWidth(2);
		g.draw(new Rectangle(x-paddleLength/2, y-paddleWidth/2, paddleLength, paddleWidth));
		g.setLineWidth(1);
		g.draw(new Rectangle(x-paddleLength/2+3, y-paddleWidth/2+3, paddleLength-6, paddleWidth-6));
	}

	@Override
	public void specialUpdate(Trackable object, float error) {
		// TODO Auto-generated method stub
		
	}
}
